import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import AddTicket from '../components/tickets/AddTicket.vue'
import CheckTicket from '../components/tickets/CheckTicket.vue'
import CheckingList from '../components/tickets/CheckingList.vue'
import PassedList from '../components/tickets/PassedList.vue'
import RefusedList from '../components/tickets/RefusedList.vue'
import UserList from '../components/user/UserList.vue'
import Permission from '../components/user/Permission.vue'
import Role from '../components/user/Role.vue'
import Report from "../components/statistics/Report.vue"
import UnresolvedFeedback from "../components/interaction/UnresolvedFeedback.vue"
import ResolvedFeedback from "../components/interaction/ResolvedFeedback"
import Announcement from "../components/interaction/Announcement.vue"

import AddBudget from '../components/equipment/AddBudget.vue'
import AddEquipment from '../components/equipment/AddEquipment.vue'
import AddPlan from '../components/equipment/AddPlan.vue'
import Attachment from '../components/equipment/Attachment.vue'
import EquipmentList from '../components/equipment/EquipmentList.vue'
import PassEquipment from "../components/equipment/PassEquipment.vue"
import RejectEquipment from "../components/equipment/RejectEquipment.vue"
import WaitEquipment from "../components/equipment/WaitEquipment.vue"

Vue.use(VueRouter)

 const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    { path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome',           component: Welcome },
        { path: '/addTicket',         component: AddTicket },
        { path: '/checkTicket',       component: CheckTicket },
        { path: '/allTicket',         component: CheckingList },
        { path: '/passedList',        component: PassedList },
        { path: '/refusedList',       component: RefusedList },
        { path: '/userList',          component: UserList },
        { path: '/powerList',         component: Permission },
        { path: '/roleList',          component: Role },
        { path: '/reports',           component: Report},
        { path: '/unresolvedFeedback',component: UnresolvedFeedback},
        { path: '/resolvedFeedback',  component: ResolvedFeedback},
        { path: '/announcement',      component: Announcement},

        { path: '/addBudget',         component: AddBudget },
        { path: '/addEquipment',      component: AddEquipment },
        { path: '/addPlan',           component: AddPlan },
        { path: '/attachment',        component: Attachment },
        { path: '/equipmentList',     component: EquipmentList },
        { path: '/passEquipment',     component: PassEquipment},
        { path: '/rejectEquipment',   component: RejectEquipment},
        { path: '/waitEquipment',     component: WaitEquipment}
      ]
    }
  ]
})
//路由导航守卫
router.beforeEach((to, from,next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next是一个函数,表示放行
  //    next() 放行   next('/login') 强制跳转
  if(to.path==='/login')
    return next()
  //获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr)
    return next('/login')
  next()
})
export default router
